﻿

//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
/* and trade secrets of Foxit Software Inc.      
**************************************************************************
*/

/**
* 负责创建Annot
*/

define(function (require, exports, module) {
    var CPDF_Annot = FXREADER.PDFData.CPDF_Annot;
    var CPDF_LinkAnnot = FXREADER.PDFData.CPDF_LinkAnnot;
    var CPDF_MarkupAnnot = FXREADER.PDFData.CPDF_MarkupAnnot;
    var AnnotDataJsonFormat = FXREADER.PDFData.AnnotDataJsonFormat;

    FXREADER.CAnnotFactory = (function () {
        var Factory =
        {
            CreateAnnot: function (jsonData,isSourceAnnot) {
                try {
                    var annot = null;
                    switch (jsonData[AnnotDataJsonFormat.type]) {
                        case "Link":
                            {
                                annot = new CPDF_LinkAnnot(jsonData);
                            }
                            break;
                        case "Markup":
                            {
                                annot = new CPDF_MarkupAnnot(jsonData);
                                var jsonAnnotGroup = jsonData[AnnotDataJsonFormat.Group];
                                if (jsonAnnotGroup) {
                                    for (var i = 0; i < jsonAnnotGroup.length; i++) {
                                        var pChildAnnot = this.CreateAnnot(jsonAnnotGroup[i],isSourceAnnot);
                                        if (pChildAnnot != null) {
                                            pChildAnnot.SetHeadAnnot(annot);
                                            annot.AddAnnot2Group(pChildAnnot);
                                        }
                                    }
                                }
                            }
                            break;
                        default: break;
                    }
                    if (annot != null) {
                    	if(isSourceAnnot != null)
                    		annot.SetSourceAnnot(isSourceAnnot);
                        //    BaseAnnotClass.EnsureAnnotInterface(annot);
                    }
                    return annot;
                }
                catch (err) {
                    throw err;
                }
            }
        };
        return Factory;
    })();


    return FXREADER.CAnnotFactory;
});